<template>
  <div>
    <div class="top">
      <el-form ref="form" :model="form" label-width="80px" inline size="mini">
        <!-- <el-form-item>
          <el-checkbox-group v-model="model">
            <el-checkbox label="label" name="name"></el-checkbox>
          </el-checkbox-group>
        </el-form-item> -->
        <el-form-item>
          <el-select v-model="form.dataType" placeholder="数据类型" clearable>
            <el-option
              :label="item"
              :value="item"
              v-for="item in dataType"
              :key="item"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="form.incomeExpensesType"
            placeholder="收支类型"
            clearable
          >
            <el-option label="支出" value="支出"></el-option>
            <el-option label="收入" value="收入"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="查询时间">
          <el-date-picker
            v-model="time"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column :prop="item.prop" :label="item.label" v-for="item in tableHeard" :key="item.prop" align="center">
      </el-table-column>
      <!-- 无数据 -->
      <template slot="empty">
        <div class="noData">
          <!--  v-show="data.length===0" -->
          <img src="@/assets/images/noData.png" />
          <p>暂无数据</p>
        </div>
      </template>
    </el-table>
    <Pagination :total="total" @pagination="handlePage" :page.sync="form.pageNum"></Pagination>
  </div>
</template>

<script>
import { dataType,tableHeard } from "./constant/index.js";
import { getList } from "@/api/financial-management/index.js";
export default {
  data() {
    return {
      total:0,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e6;
        },
      },
      time: [],
      tableData: [],
      form: {
        dataType: "",
        startTime: "",
        endTime: "",
        // id: null,
        incomeExpensesType: "",
        pageNum: 0,
        pageSize: 10
      },
      dataType,
      tableHeard
    };
  },
  created() {
    this.getTableList();
  },
  methods: {
    async getTableList() {
      let res = await getList(this.form);
      if (res.code == 200) {
        this.tableData = res.data.records
        this.total = res.data.total
      }
    },
    handlePage(val) {
      this.form.pageNum = val.page;
      this.form.pageSize = val.limit;
      this.getTableList();
    },
    search(){
      this.form.pageNum = 1
      this.getTableList()
    }
  },
  watch: {
    time(newValue) {
      if (newValue) {
        this.form.startTime = newValue[0];
        this.form.endTime = newValue[1];
      } else {
        this.form.startTime = "";
        this.form.endTime = "";
      }
    },
  }
};
</script>

<style></style>
